///////////////////////////////////////////////////////////
// 
//  Player.h
//
//  Wiicussion
//  HCI 575 Class project
//  Spring 2007
// 
//  Authors:  Jeremy Bennett
//            Adam Faeth
//            Michael Oren
//
///////////////////////////////////////////////////////////

#ifndef _PLAYER_H_
#define _PLAYER_H_

// Local Includes
#include "MyImage.h"

// HaptCtrl Includes
#include <HaptWiimote.h>

// SDL Includes
#include <sdl.h>

// System Includes

// Forward Declarations
class MyContext;

class Player
{
  public:
    Player();
    ~Player();

    bool setID( int id ) { _uID = id; return true; }
    int  id()            { return _uID; }
    
#if defined(USE_GLOVEPIE)
    bool setJoystick( SDL_Joystick *pJoy1, SDL_Joystick *pJoy2 );
    SDL_Joystick* joystick() { return _pJoystick[0]; }
	SDL_Joystick* joystick2() { return _pJoystick[1]; }
#else
    // Note: Users must go through the player class in order to
    //       get the relevant Wiimote state.
    bool setWiimote( HaptWiimote *pMote1, HaptWiimote *pMote2 );
#endif

    bool toggleActive();

    bool setUIPosition( float x, float y, float w, float h );
    bool setRendPosition( const float *pPos );
    
    void setState(bool state) { _bActive = state; }

    int  instrument( int iMote ) { return _instrument[iMote%2]; }
    bool calibrateInstuments( float x, float y, float w, float h, float s, float e );

    int  score()          { return _horseScore; }
    void resetScore()     { _horseScore = 5;    }
    void decrementScore() {	if(_horseScore > 0) _horseScore--; }

#if defined(USE_GLOVEPIE)
    // DEPRECATED:
	bool getButton(int iButton);
    bool getButton2(int iButton);
    void setButton(int iButton, bool pressed);
	void setButton2(int iButton, bool pressed);
#else
    bool isButtonPressed( int iMote, HaptWiimoteButton iButton );
    bool isPlayingNote( int iMote ) { return _bNote[iMote%2]; }
	bool getPosition(int iMote, float &x, float &y){
		x = _fPoint[iMote%2][0];
		y = _fPoint[iMote%2][1];
		return true;
	}
	bool setRumble(int iMote, bool state){
		if(_pMote[iMote] != NULL)
			_pMote[iMote]->setRumble(state);
		return true;
	}
	bool getRumble(int iMote){
		if(_pMote[iMote] != NULL)
			return _pMote[iMote]->rumble();
		else
			return false;
	}
#endif

    bool preFrame();
    bool postFrame();

    bool renderPointer( MyContext *pContext=NULL );
    bool renderPlayer( MyContext *pContext=NULL );

  protected:
    bool _updateState( int iMote );
    bool _updateInstrument( int iMote );

  protected:
    bool              _bActive;
    int               _uID;
    int               _horseScore;
    bool              _bActiveGamePlayer;

    int               _instrument[2];
    float             _fInstrWnd[4];
    float             _iInstrRange[2];

#if defined(USE_GLOVEPIE)
    // DEPRECATED:

    // SDL Joystick
    SDL_Joystick     *_pJoystick[2];

    //Mike Oren: Store button presses
	bool			 _bButtonArr[11];
	bool			 _bButtonArr2[11];
#else
    // HaptCtrl Wiimote
    HaptWiimote      *_pMote[2];
#endif
	    
    // Player UI Rendering
    float             _fUISize[2];
    float             _fUIPos[2];

    // Player Description
    float             _fColor[4];

    // Player Location
    float             _fPoint[2][2];
    float             _fLocation[3];
    float             _fDirection[3];

    // Player
    bool              _bNote[2];
    float             _fAccel[2][3];

    char              _cBuffer[256];
    
    static bool s_bVerbose;

	int _rumbleCount;
	
};

#endif // _PLAYER_H_
